home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / javax / swing / MultiUIDefaults.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  3.1 KB  |  163 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)MultiUIDefaults.java    1.8 98/08/26
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package javax.swing;
  16.  
  17. import java.util.Enumeration;
  18.  
  19.  
  20.  
  21. /**
  22.  * 
  23.  * @version 1.8 08/26/98
  24.  * @author Hans Muller
  25.  */
  26. class MultiUIDefaults extends UIDefaults
  27. {
  28.     private UIDefaults[] tables;
  29.  
  30.     public MultiUIDefaults(UIDefaults[] defaults) {
  31.     super();
  32.     tables = defaults;
  33.     }
  34.  
  35.     public MultiUIDefaults() {
  36.     super();
  37.     tables = new UIDefaults[0];
  38.     }
  39.  
  40.  
  41.     public Object get(Object key) 
  42.     {
  43.     Object value = super.get(key);
  44.     if (value != null) {
  45.         return value;
  46.     }
  47.  
  48.     for(int i = 0; i < tables.length; i++) {
  49.         UIDefaults table = tables[i];
  50.         value = (table != null) ? table.get(key) : null;
  51.         if (value != null) {
  52.         return value;
  53.         }
  54.     }
  55.  
  56.     return null;
  57.     }
  58.  
  59.  
  60.     public int size() {
  61.     int n = super.size();
  62.     for(int i = 0; i < tables.length; i++) {
  63.         UIDefaults table = tables[i];
  64.         n += (table != null) ? table.size() : 0;
  65.     }
  66.     return n;
  67.     }
  68.  
  69.  
  70.     public boolean isEmpty() {
  71.     return size() == 0;
  72.     }
  73.  
  74.  
  75.     public Enumeration keys() 
  76.     {
  77.     Enumeration[] enums = new Enumeration[1 + tables.length];
  78.     enums[0] = super.keys();
  79.     for(int i = 0; i < tables.length; i++) {
  80.         UIDefaults table = tables[i];
  81.         if (table != null) {
  82.         enums[i + 1] = table.keys();
  83.         }
  84.     }
  85.     return new MultiUIDefaultsEnumerator(enums);
  86.     }
  87.  
  88.  
  89.     public Enumeration elements() 
  90.     {
  91.     Enumeration[] enums = new Enumeration[1 + tables.length];
  92.     enums[0] = super.elements();
  93.     for(int i = 0; i < tables.length; i++) {
  94.         UIDefaults table = tables[i];
  95.         if (table != null) {
  96.         enums[i + 1] = table.elements();
  97.         }
  98.     }
  99.     return new MultiUIDefaultsEnumerator(enums);
  100.     }
  101.  
  102.  
  103.     private static class MultiUIDefaultsEnumerator implements Enumeration
  104.     {
  105.     Enumeration[] enums;
  106.     int n = 0;
  107.  
  108.     MultiUIDefaultsEnumerator(Enumeration[] enums) {
  109.         this.enums = enums;
  110.     }
  111.  
  112.     public boolean hasMoreElements() {
  113.         for(int i = n; i < enums.length; i++) {
  114.         Enumeration e = enums[i];
  115.         if ((e != null) && (e.hasMoreElements())) {
  116.             return true;
  117.         }
  118.         }
  119.         return false;
  120.     }
  121.  
  122.     public Object nextElement() {
  123.         for(; n < enums.length; n++) {
  124.         Enumeration e = enums[n];
  125.         if ((e != null) && (e.hasMoreElements())) {
  126.             return e.nextElement();
  127.         }
  128.         }
  129.         return null;
  130.     }
  131.     }
  132.  
  133.  
  134.     public Object remove(Object key) 
  135.     {
  136.     Object value = super.remove(key);
  137.     if (value != null) {
  138.         return value;
  139.     }
  140.  
  141.     for(int i = 0; i < tables.length; i++) {
  142.         UIDefaults table = tables[i];
  143.         value = (table != null) ? table.remove(key) : null;
  144.         if (value != null) {
  145.         return value;
  146.         }
  147.     }
  148.  
  149.     return null;
  150.     }
  151.  
  152.  
  153.     public void clear() {
  154.     super.clear();
  155.     for(int i = 0; i < tables.length; i++) {
  156.         UIDefaults table = tables[i];
  157.         if (table != null) {
  158.         table.clear();
  159.         }
  160.     }
  161.     }
  162. }
  163.